package com.renrencai.quartz.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean(name = "rrcDataSource")
    @Qualifier("rrcDataSource")
    @ConfigurationProperties(prefix = "hikari.rrc")
    public DataSource rrcDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "lotteryDataSource")
    @Qualifier("lotteryDataSource")
    @ConfigurationProperties(prefix = "hikari.lottery")
    public DataSource lotteryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "rrcJdbcTemplate")
    public JdbcTemplate rrcJdbcTemplate(@Qualifier("rrcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "lotteryJdbcTemplate")
    public JdbcTemplate lotteryJdbcTemplate(@Qualifier("lotteryDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
